﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleForeach
{
    public class IteratorWorkflow
    {
        public static IEnumerable Power(int number, int exponent)
        {
            int counter = 0;
            int result = 1;
            while (counter++ < exponent)
            {
                result = result * number;
                yield return result;
            }
        }

        static void Main()
        {
            //var x = Test();
            //// Display powers of 2 up to the exponent 8:
            //foreach (int i in Power(2, 8))
            //{
            //    Console.Write("{0} ", i);
            //}

            var list = new List<string> { "1", "2", "3", "4" };
            list.ForEach(l => Console.WriteLine($"{l},thread Id={Thread.CurrentThread.ManagedThreadId}"));

            Console.ReadLine();
        }

        private static IEnumerable Test()
        {
            var list = new List<int> { 1, 3, 2, 2, 3, 3 };
            foreach (var number in list)
            {
                if (number != 3) yield return number;
            }
        }
    }

}
